home *** CD-ROM | disk | FTP | other *** search
/ Pascal Super Library / Pascal Super Library (CW International)(1997).bin / MATH / NRPAS13 / F1DIM.DEM < prev    next >
Text File  |  1991-04-29  |  1KB  |  54 lines

  1. PROGRAM d10r8(input,output);
  2. (* driver for routine F1DIM *)
  3. CONST
  4.    ndim=3;
  5. TYPE
  6.    glndim = ARRAY [1..ndim] OF real;
  7. VAR
  8.    i,j,ncom : integer;
  9.    p,xi : glndim;
  10.    pcom,xicom : glndim;
  11.  
  12. FUNCTION fnc(x : glndim) : real;
  13. (* Programs using routine FNC must define the type
  14. TYPE
  15.    glndim = ARRAY [1..ndim] OF real;
  16. in the main routine, where ndim is the dimension of vector x. *)
  17. VAR
  18.    f : real;
  19.    i : integer;
  20. BEGIN
  21.    f := 0.0;
  22.    FOR i := 1 to 3 DO BEGIN
  23.       f := f+sqr(x[i]-1.0)
  24.    END;
  25.    fnc := f
  26. END;
  27.  
  28. (*$I MODFILE.PAS *)
  29. (*$I F1DIM.PAS *)
  30.  
  31. FUNCTION fx(x: real): real;
  32. BEGIN
  33.    fx := f1dim(x)
  34. END;
  35.  
  36. (*$I SCRSHO.PAS *)
  37.  
  38. BEGIN
  39.    p[1] := 0.0; p[2] := 0.0; p[3] := 0.0;
  40.    ncom := ndim;
  41.    writeln;
  42.    writeln('Enter vector direction along which to');
  43.    writeln('plot the function. Minimum is in the');
  44.    writeln('direction 1.0 1.0 1.0 - enter x y z:');
  45.    read(xi[1],xi[2],xi[3]);
  46. FOR i := 1 to 3 DO write(xi[i]);
  47. writeln;
  48.    FOR j := 1 to ndim DO BEGIN
  49.       pcom[j] := p[j];
  50.       xicom[j] := xi[j]
  51.    END;
  52.    scrsho
  53. END.
  54.